﻿using MCUPackage.DesignEditor;
using Newtonsoft.Json;
using System;
using System.ComponentModel;

namespace SxPackages.STC8.Models
{
	[Serializable]
	class AllSPIOptions
	{
		/// <summary>
		/// 串口配置结合
		/// </summary>
		[Browsable(false),
		JsonIgnore]
		public SPIOptionBase[] All { get; private set; }

		[Category("SPI配置"),
		DisplayName("通用SPI"),
		TypeConverter(typeof(PropertySorter))]
		public SPIOptions SPI { get; private set; }

		[Category("SPI配置"),
		DisplayName("模拟SPI口"),
		TypeConverter(typeof(PropertySorter))]
		public SoftSPIOptions Soft { get; private set; }

		public AllSPIOptions(STC8HUSOP20 aParent)
		{
			this.SPI = new SPIOptions(aParent);
			this.Soft = new SoftSPIOptions(aParent);
			All = new SPIOptionBase[] { this.SPI, Soft };
		}

		public bool HasEnabled()
		{
			foreach (var spi in this.All)
			{
				if (spi.Enable)
				{
					return true;
				}
			}

			return false;
		}
	}
}
